package com.esiag.pdsteam.referencement.dao;

import java.sql.Connection;
import java.sql.DriverManager;


public class DataSource {
	private String driver;
	private String url;
	private String user;
	private String pwd;
	
	public DataSource(String driver, String url, String user, String pwd) {
		super();
		this.driver = driver;
		this.url = url;
		this.user = user;
		this.pwd = pwd;
	}
	
	public Connection getConnection () {
		try {
			Class.forName(driver);
			Connection db;
			if(user.isEmpty())
				db = DriverManager.getConnection(url);
			else
			    db = DriverManager.getConnection(url, user, pwd);
			System.out.println("Connection établie avec succès");
			return db;
		} catch (Exception e) {
			System.out.println("Erreur de connection avec la base de données");
			return null;
		}
	}
}

